import type {
  User,
  CodeType,
  UserInfo,
  PatientList,
  Patient
} from '@/types/user'
import request from '@/utils/request'

//密码登录
export const loginPassword = (mobile: string, password: string) => {
  return request<User>('login/password', 'post', { mobile, password })
}

//获取验证码
export const getCode = (mobile: string, type: CodeType) => {
  return request<{ code: string }>('code', 'get', {
    mobile,
    type
  })
}

//验证码登录
export const loginCode = (mobile: string, code: string) => {
  return request<User>('login', 'post', {
    mobile,
    code
  })
}

// 获取个人信息
export const getUserInfo = () => request<UserInfo>('/patient/myUser')

// 获患者信息列表
export const getPatientList = () => request<PatientList>('/patient/mylist')

// 添加患者信息
export const addPatient = (patient: Patient) =>
  request('/patient/add', 'POST', patient)

// 编辑患者信息
export const editPatient = (patient: Patient) =>
  request('/patient/update', 'PUT', patient)

// 删除患者信息
export const delPatient = (id: string) =>
  request(`/patient/del/${id}`, 'DELETE')

// 查询患者详情
export const getPatientDetail = (id: string) =>
  request<Patient>(`/patient/info/${id}`)

//qq登录
export const loginByQQ = (openId: string) =>
  request<User>('/login/thirdparty', 'POST', { openId, source: 'qq' })

//绑定手机号
export const bindMobile = (data: {
  mobile: string
  code: string
  openId: string
}) => request<User>('/login/binding', 'POST', data)

//获取消息数量
export const msgNumber = () =>
  request<number>('/patient/message/unRead/all', 'GET')
